package com.wish233.wiliwilivideo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wish233.wiliwiliapi.domain.vo.VideoVO;
import com.wish233.wiliwilivideo.domain.dto.video.VideoStatusRequest;
import com.wish233.wiliwilivideo.domain.po.Video;
import com.wish233.wiliwilivideo.service.AdminService;
import com.wish233.wiliwilivideo.service.VideoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author WHH
 * 管理员审核
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private VideoService videoService;

    @Override
    public List<VideoVO> listNotReviewed(Integer current, Integer pageSize) {
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 0);
        Page<Video> page = videoService.page(new Page<>(current, pageSize), queryWrapper);
        if (CollectionUtil.isEmpty(page.getRecords())) {
            return Collections.emptyList();
        }
        return page.getRecords()
                .stream()
                .map(v -> BeanUtil.copyProperties(v, VideoVO.class))
                .collect(Collectors.toList());
    }

    @Override
    public Boolean setStatus(VideoStatusRequest videoStatusRequest) {
        Long id = videoStatusRequest.getId();
        Integer status = videoStatusRequest.getStatus();
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id).eq("status", status);
        return videoService.update(queryWrapper);
    }


}
